<template>
  <rx-layout>
      <div slot="left" width="220" showButton="true">
          <rx-fit>
              <rx-category-treeeditor
                  cat-key="API"
                  :statisticConfig="statisticConfig"
                  :edit="true"
                  @handSelect="handSelect"
                  :async="true"
                  v-if="isShowManageTree"
                  :isAdmin="isManageToTree"
                  :checkToDel="true">
              </rx-category-treeeditor>
          </rx-fit>
      </div>
    <div slot="center" showButton="true" >
      <rx-fit>
        <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
          <div class="table-operator">
            <a-button type="primary" icon="plus" @click="addProject">
                {{$ti18('rxList.newBtn','新建')}}
            </a-button>
              <a-button v-if="selectedRowKeys.length > 0"
                        type="primary"
                        icon="switcher" @click="openCategoryDialog">
                  {{$ti18('rxList.changeCategory','切换分类')}}
              </a-button>
            <a-dropdown v-if="editEnable && selectedRowKeys.length > 0 || removeEnable && selectedRowKeys.length > 0">
              <a-button style="margin-left: 8px">
                  {{$ti18('rxList.moreBtn','更多')}}
                  <a-icon type="down" /> </a-button>
              <a-menu slot="overlay">
                <a-menu-item key="1" v-if="editEnable && selectedRowKeys.length > 0" alias="sysInterfaceProjectEdit" :butn-icon="'edit'"
                             :butn-type="'primary'" :show-no-right="false" @click="editOne"><a-icon type="user"  />
                    {{$ti18('rxList.editBtn', '编辑')}}
                </a-menu-item>
                <a-menu-item key="2" v-if="removeEnable && selectedRowKeys.length > 0" alias="sysInterfaceProjectDelete" :butn-icon="'delete'" :butn-type="'danger'"
                             :show-no-right="false" @click="delByIds(selectedRowKeys)"><a-icon type="delete" />
                    {{$ti18('rxList.delBtn','删除')}}
                </a-menu-item>
                  <a-menu-item
                      key="3"
                      @click="changeExport(exportConf)"
                      v-if="selectedRowKeys.length > 0"
                      alias="formRuleDelete"
                      :butn-type="'primary'"
                      :show-no-right="false"
                  >
                      <a-icon type="switcher"/>
                      {{$ti18('rxList.changeExport','切换导出')}}
                  </a-menu-item>
              </a-menu>
            </a-dropdown>
          </div>
          <span class="search-btn-box">
                <span class="search-btn" @click="searchshow"><i class="iconfont iconguolv"></i>
                    {{$ti18('rxList.leachBtn','过滤')}}
                </span>
           </span>
        </div>
        <div slot="searchbar" btnalign="right"  v-if="fitSearch" @search="search" @cancel="cancel" @close="close">
          <a-form layout="vertical">
                <a-form-item :label="i18n('form.projectAlias','项目别名')">
                    <a-input :placeholder="i18n('form.projectAlias','项目别名','input')" v-model="queryParam.Q_PROJECT_ALIAS__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('form.projectName','项目名称')">
                    <a-input :placeholder="i18n('form.projectName','项目名称','input')" v-model="queryParam.Q_PROJECT_NAME__S_LK"/>
                </a-form-item>
                <a-form-item :label="i18n('form.projectStatus','项目状态')">
                    <a-select style="width: 100%" :placeholder="i18n('form.projectStatus','项目状态','input')" v-model="queryParam.Q_STATUS__S_LK">
                        <a-select-option value="">
                            {{i18n('isProjectStatusMap.select','请选择')}}
                        </a-select-option>
                        <a-select-option value="YES">
                            {{i18n('isProjectStatusMap.enable','启用')}}
                        </a-select-option>
                        <a-select-option value="NO">
                            {{i18n('isProjectStatusMap.disable','禁用')}}
                        </a-select-option>
                    </a-select>
                </a-form-item>
          </a-form>
        </div>
        <rx-grid
                ref="table"
                :bordered="isBorder"
                :allowRowSelect="true"
                :multiSelect="true"
                :columns="columns"
                :defaultPageSize="10"
                url="/api-system/system/core/sysInterfaceProject/query"
                :queryParam="queryParam"
                data-field="result.data"
                :pageSizeOptions="['10','30','40']"
                id-field="projectId"
                @selectChange="onSelectChange"
        >
             <span slot="exportApp">
                  {{ exportI18n('export.isExport','导出') }}
                 <export-app/>
             </span>
            <span slot="status" slot-scope="{ text, record }">
                <a-tag :color="statusMap[text].color">
                  <span>{{ statusMap[text].text }}</span>
                </a-tag>
            </span>
            <span slot="isExport" slot-scope="{ text, record }">
                <a-tag :color="text == 1 ? 'green' : 'red'">
                    <span>{{ text == 1 ? exportI18n('export.yes','是') : exportI18n('export.no','否') }}</span>
                </a-tag>
            </span>
            <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                <span v-if="editEnable" @click.stop="edit(record)">
                    {{$ti18('rxList.editBtn', '编辑')}}
                </span>
                <span v-if="removeEnable" @click.stop="delByIds([record.projectId])">
                    {{$ti18('rxList.delBtn','删除')}}
                </span>
                <span @click="setExport(record,exportConf)">{{record.isExport == 1 ? exportI18n('export.noExport','不导出') : exportI18n('export.exported','导出')}}</span>
                <span v-if="!curApp.appId" @click="share(record)">{{$ti18('rxList.share','共享')}}</span>
            </span>
        </rx-grid>
      </rx-fit>
    </div>
  </rx-layout>
</template>

<script>
  import SysInterfaceProjectApi from '@/api/system/core/sysInterfaceProject'
  import SysInterfaceProjectAdd from './SysInterfaceProjectAdd'
  import SysInterfaceProjectEdit from './SysInterfaceProjectEdit'
  import {BaseList, Dialog, RxFit, RxGrid} from "@lowcode/jpaas-common-lib";
  import RxCategoryTreeeditor from '@/components/redxun/rx-category-treeeditor'

  import exportApp from "@/views/modules/share/exportApp";
  import FormResourceShareApi from "@/api/form/core/formResourceShare";
  import switchExport from "@/utils/switchExport";
  import ChangeCategory from "@/views/modules/share/ChangeCategory.js"
  export default {
    name: 'SysInterfaceProjectList',
    mixins: [BaseList,switchExport,ChangeCategory],
    components: {
        RxGrid,
        RxFit,
        RxCategoryTreeeditor,
        exportApp
    },
    created() {
        this.isUserManager(this.$route.query.appId);
        this.needFilterAppId();
    },
    data() {
      return {
        columns: [
          {
            title: this.$ti18('rxList.index','序号'),
            type: 'indexColumn',
            width: 50,
            dataIndex: 'serial',
            scopedSlots: {customRender: 'serial'}
          },
            {title: this.i18n('form.projectName','名称'), dataIndex: 'projectName', width: 120},
          {title: this.i18n('form.projectAlias','别名'), dataIndex: 'projectAlias', width: 100},
          {title: this.i18n('form.domain','域名路径'), dataIndex: 'domainFullPath', width: 100},
          {title: this.i18n('form.projectStatus','项目状态'), dataIndex: 'status', width: 50, scopedSlots: {customRender: 'status'}},
          {
              dataIndex: 'isExport',
              slots: { title: 'exportApp' },
              width: 80,
              scopedSlots: {customRender: 'isExport'}
          },
            {title: this.$ti18('rxForm.createTime','创建时间'), dataIndex: 'createTime', width: 120},
          {title: this.$ti18('rxList.action','操作'), width: 120, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
        ],
        component:SysInterfaceProjectEdit,
        comment:this.i18n('form.itemList','接口项目表'),
        fitSearch:false,
        curTree: {},
        statusMap: {
            'YES': {color: 'green', text: this.i18n('isProjectStatusMap.enable','启用')},
            'NO': {color: 'red', text: this.i18n('isProjectStatusMap.disable','禁用')}
        },
        statisticConfig: {
          type:"static_system",
          table:"SYS_INTERFACE_PROJECT t",
          field:"TREE_ID_",
          whereConf:[]
        },
        /**
         * 导出配置
         */
        exportConf:{
            Api:SysInterfaceProjectApi,
            id:"projectId"
        },
          //变更分类配置
          categoryConfig:{
              Api:SysInterfaceProjectApi,
              catKey:"API",
              gridRef:"table"
          }
      }
    },
    methods:{
        i18n(name, text, key) {
            return this.$ti18(name, text, "sysInterfaceProject", key);
        },
        exportI18n(name,text,key){
            return this.$ti18(name,text,"appExport",key);
        },
        share(record){
            let self=this;
            FormResourceShareApi.getShareApps(record.pkId).then(res => {
                let initData=res.data;
                if(!initData){
                    initData=[];
                }
                self.showAppDialog(initData,record.pkId,record.projectAlias,record.projectName);
            });
        },
        showAppDialog(initData,resId,resKey,resName){
            Dialog.openSystemAppDialog({
                curVm: this, widthHeight: ['1150px', '735px'],
                data:{initSelected: initData,isDevelopApp:true,isSelectApp:true}
            }, function (self, data) {
                //保存共享信息
                FormResourceShareApi.saveShareApps(data.apps,resId,resKey,resName,"6").then(res => {
                    if (res.success && res.code == 200) {
                    }
                });
            })
        },
      //fsad
      delById(ids){
        return SysInterfaceProjectApi.del({ ids: ids.join(',') });
      },
      getListByParams(parameter){
        return SysInterfaceProjectApi.query(parameter)
      },
      search(){
        this.$refs.table.loadData()
      },
      cancel(){
        this.resetSearch();
      },
      close(){
        //关闭按钮
        this.fitSearch = false ;
      },
      handSelect(curRow){
          this.curTree = curRow
          var treeId = curRow.treeId
          if(treeId=='0'){
              treeId='';
          }
          this.loadData({Q_TREE_ID__S_EQ: treeId})
      },
      addProject(){
          var conf = {
              component: SysInterfaceProjectAdd,
              title: this.$ti18('rxList.newBtn','添加') + "-" + this.comment,
              urlType: 'Add',
              widthHeight:['700px','600px']
          };
          this.handleEdit(conf);
      }
    }
  }
</script>
<style scoped>

</style>

